const DB = require('../../utils/db.js');

Page({

  data: {
    disabled: false,
    btnstate: "primary",
  },

  //点击登录事件
  login:function(e){
    var name = e.detail.value.name;
    var pwd = e.detail.value.password;
    if(name != "" && pwd != ""){
      wx.showToast({
        title: '正在登录...',
        icon: 'loading',
        mask:true
      })
      DB.getPolice(name,function(res){
      // console.log(res)
      if(res.length != 0){
        if(res[0].password == pwd && res[0].status == 1){
          wx.clearStorageSync();
          wx.setStorageSync('police', {'name':name,'login':true});

          //关闭所有页面打开新页面
          wx.reLaunch({
            url: '/pages/policelogin/scan/scan?name='+name,
          })


        }else{
          wx.showToast({
            title: '密码错误或账户已停用，请联系管理员！',
            icon:'none'
          })
        }
      }else{
        wx.showToast({
          title: '账号或密码错误！',
          icon:'none'
        })
      }
    });
    }else{
      wx.showToast({
        title: '请输入账号密码!',
        icon:'none'
      })
    }
    

  }
})